package gather;

import java.util.ArrayList;

/*
main方法中定义一个集合，存三个用户对象，用户属性为：id，username，password
根据id查找用户信息，存在返回true,不存在返回false
 */
public class G6 {
    public static void main(String[] args) {
        ArrayList<User> list = new ArrayList<>();
        //创建三个对象
        User u1=new User("张三","u1","a1");
        User u2=new User("txt","u2","a2");
        User u3=new User("job","u3","a3");
        //把用户添加集合
        list.add(u1);
        list.add(u2);
        list.add(u3);
        //调方法打结果
        boolean flag=contains(list,"u1");
        System.out.println(flag);
    }
    public static boolean contains(ArrayList<User> list,String id){
        for (int i = 0; i < list.size(); i++) {
            if (list.get(i).getId().equals(id)) {
                return true;
            }
        }
        return false;
    }

}
